| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | "use strict"; |
||
| 15 | describe ('printable-characters', () => { |
||
| 16 | |||
| 17 | it ('determines visible length', () => { |
||
| 18 | |||
| 19 | assert.equal (strlen ('💩'), 1) |
||
| 20 | //assert.equal (strlen ('👩❤️💋👩'), 1) // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution |
||
| 21 | assert.equal (strlen ('❤️'), 1) |
||
| 22 | assert.equal (strlen ('foo bar'), 7) |
||
| 23 | assert.equal (strlen ('\u001b[106mfoo bar\u001b[49m'), 7) |
||
| 24 | }) |
||
| 25 | |||
| 26 | it ('detects blank text', () => { |
||
| 27 | |||
| 28 | assert (!isBlank ('💩')) |
||
| 29 | assert (!isBlank ('foobar')) |
||
| 30 | assert ( isBlank ('\u001b[106m \t \t \n \u001b[49m')) |
||
| 31 | }) |
||
| 32 | |||
| 33 | it ('matches zero-width characters and ANSI escape codes', () => { |
||
| 34 | |||
| 35 | let s = '\u001b[106m' + 'foo' + '\n\n' + 'bar' + '\u001b[49m' |
||
| 36 | |||
| 37 | assert (s = s.replace (ansiEscapeCodes, ''), 'foo\n\nbar') |
||
| 38 | assert ( s.replace (zeroWidthCharacters, ''), 'foobar') |
||
| 39 | }) |
||
| 40 | |||
| 41 | it ('obtains blank string of the same width', () => { |
||
| 42 | |||
| 43 | assert.equal (blank ('💩'), ' ') |
||
| 44 | //assert.equal (blank ('👩❤️💋👩'), ' ') // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution |
||
| 45 | assert.equal (blank ('❤️'), ' ') |
||
| 46 | assert.equal (blank ('foo'), ' ') |
||
| 47 | assert.equal (blank ('\n'), '\n') |
||
| 48 | assert.equal (blank ('\t'), '\t') |
||
| 49 | assert.equal (blank ('\tfoo \nfoo'), '\t \n ') |
||
| 50 | assert.equal (blank ('\u001b[22m\u001b[1mfoo \t\u001b[39m\u001b[22m'), ' \t') |
||
| 51 | }) |
||
| 52 | |||
| 53 | it ('extracts invisible parts followed by visible ones', () => { |
||
| 54 | |||
| 55 | assert.deepEqual (partition (''), [ ]) |
||
| 56 | assert.deepEqual (partition ('foo'), [['', 'foo'] ]) |
||
| 57 | assert.deepEqual (partition ('\u001b[1mfoo'), [['\u001b[1m', 'foo'] ]) |
||
| 58 | assert.deepEqual (partition ('\u001b[1mfoo\u0000bar'), [['\u001b[1m', 'foo'], ['\u0000', 'bar'] ]) |
||
| 59 | assert.deepEqual (partition ('\u001b[1mfoo\u0000bar\n'), [['\u001b[1m', 'foo'], ['\u0000', 'bar'], ['\n', '']]) |
||
| 60 | }) |
||
| 61 | |||
| 62 | it ('gets first N visible symbols (preserving invisible parts)', () => { |
||
| 63 | |||
| 64 | assert.equal (first ('💩23456789', 0), '') |
||
| 65 | assert.equal (first ('💩23456789', 3), '💩23') |
||
| 66 | assert.equal (first ('💩23456789', 100), '💩23456789') |
||
| 67 | |||
| 68 | const s = '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '45' + '\u001b[39m' + '67' + '\n' + '89' + '\u001b[39m\u001b[22m' |
||
| 69 | |||
| 70 | assert.equal (first (s, 0), '\u001b[22m\u001b[1m' + '' + '\u0000' + '' + '\u001b[39m' + '' + '\n' + '' + '\u001b[39m\u001b[22m') |
||
| 71 | assert.equal (first (s, 3), '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '' + '\u001b[39m' + '' + '\n' + '' + '\u001b[39m\u001b[22m') |
||
| 72 | assert.equal (first (s, 4), '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '4' + '\u001b[39m' + '' + '\n' + '' + '\u001b[39m\u001b[22m') |
||
| 73 | assert.equal (first (s, 6), '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '45' + '\u001b[39m' + '6' + '\n' + '' + '\u001b[39m\u001b[22m') |
||
| 74 | assert.equal (first (s, 9), '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '45' + '\u001b[39m' + '67' + '\n' + '89' + '\u001b[39m\u001b[22m') |
||
| 75 | assert.equal (first (s, 100), '\u001b[22m\u001b[1m' + '💩23' + '\u0000' + '45' + '\u001b[39m' + '67' + '\n' + '89' + '\u001b[39m\u001b[22m') |
||
| 76 | }) |
||
| 77 | }) |